<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/5/18
 * Time: 16:07
 */

namespace Home\Model\Apply;


use Think\Model;

class ApplyModel extends Model
{
    public function addApply($apply)
    {
        return $this->add($apply);
    }

    public function checkApply($user_id)
    {
        return $this->where(array('user_id' => $user_id))->field('id')->find();
    }

    public function selectApply($order, $limit, $keyword, $act_id)
    {
        $keyword = '%' . $keyword . '%';
        $map['name'] = array('like', $keyword);
        $map['act_id'] = $act_id;

        if (is_null($order)) {
            return $this->order('id asc')->where($map)->limit($limit)->select();
        } else {
            return $this->order($order . ' desc')->where($map)->limit($limit)->select();
        }
    }

    public function findApply($apply_id)
    {
        return $this->find($apply_id);
    }

    public function addNum($apply_id)
    {
        return $this->where(array('id' => $apply_id))->setInc('vote_num');
    }

    /*public function saveTime($apply_id, $time)
    {
        return $this->where(array('id' => $apply_id))->save(array('last_time' => $time));
    }*/
}